﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:n="http://nRoute/schemas/2010/xaml"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    mc:Ignorable="d" 
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:nRoute_Samples_OfficerXcel_Controls="clr-namespace:nRoute.Samples.OfficerXcel.Controls;assembly=OfficerXcel.Infrastructure" 
	xmlns:xCelBehaviors="clr-namespace:nRoute.Samples.OfficerXcel.Behaviors;assembly=OfficerXcel.Infrastructure" 
    x:Class="nRoute.Samples.OfficerXcel.Views.WorksheetView" 
    d:DesignWidth="680" d:DesignHeight="500">
	
    <!-- RESOURCES -->
	<UserControl.Resources>		
		<n:ValueRelay x:Key="CurrentColumnHeaderValueRelay" />
		<n:ValueConverterRelay x:Key="WorksheetNotNullConverterRelay" />		
	</UserControl.Resources>
	
    <!-- VIEW-MODEL ATTACHING -->
	<i:Interaction.Behaviors>
        <n:BridgeViewModelBehavior/>
    </i:Interaction.Behaviors>
	
	<Grid x:Name="LayoutRoot">
	
		<Grid.RowDefinitions>
			<RowDefinition Height="91"/>
			<RowDefinition Height="25"/>
			<RowDefinition/>
		</Grid.RowDefinitions>
		
		<!-- TOOLBAR --> 
		<Border BorderBrush="#FFB6BABF" BorderThickness="0,0,0,1" Height="91" VerticalAlignment="Top">
			<i:Interaction.Behaviors>
				<n:NullValueDisableBehavior Value="{Binding Worksheet, Mode=OneWay}"/>
			</i:Interaction.Behaviors>
                
				<Border.Background>
					<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
						<GradientStop Color="#FFE8EBEF" Offset="0.875"/>
						<GradientStop Color="White"/>
					</LinearGradientBrush>
				</Border.Background>
                
				<StackPanel Orientation="Horizontal">
                    
					<!-- CLIPBOARD PANEL -->
					<Border Width="78" BorderThickness="0,0,1,0" Margin="2,0">
						<Border.BorderBrush>
							<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
								<GradientStop Color="#FFE0D8D8" Offset="0.185"/>
								<GradientStop Color="Transparent" Offset="0.992"/>
								<GradientStop Color="#00B9B9B9"/>
								<GradientStop Color="#FFE0D8D8" Offset="0.91"/>
							</LinearGradientBrush>
						</Border.BorderBrush>
						<Grid>
							<Grid.ColumnDefinitions>
								<ColumnDefinition/>
								<ColumnDefinition Width="28"/>
							</Grid.ColumnDefinitions>
							<Grid.RowDefinitions>
								<RowDefinition Height="0.5*"/>
								<RowDefinition Height="0.5*"/>
								<RowDefinition Height="21"/>
							</Grid.RowDefinitions>
							<TextBlock Grid.Row="2" Text="Clipboard" TextWrapping="Wrap" 
								HorizontalAlignment="Center" VerticalAlignment="Center" 
								Foreground="#FF929292" Grid.ColumnSpan="2" FontSize="9.333"/>
							<nRoute_Samples_OfficerXcel_Controls:ImageButton Content="Paste" ImageSource="/OfficerXcel.Content;Component/Icons/Paste.png" 
								Style="{StaticResource ToolbarOfficeImageButtonStyle}" 
								Grid.RowSpan="2"/>
							<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
								Style="{StaticResource ToolbarOfficeImageButtonStyle}" 
								VerticalAlignment="Bottom" Width="28" Grid.Column="1" 
								ImageSource="/OfficerXcel.Content;Component/Icons/Cut.png"/>
							<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
								Style="{StaticResource ToolbarOfficeImageButtonStyle}" 
								Width="28" Grid.Column="1" Grid.Row="1" ImageSource="/OfficerXcel.Content;Component/Icons/Copy.png"/>
						</Grid>
					</Border>
                    
					<!-- BASIC TEXT PANEL -->
					<Border Margin="2,0" Width="340" BorderThickness="0,0,1,0">
						<Border.BorderBrush>
							<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
								<GradientStop Color="#FFE0D8D8" Offset="0.185"/>
								<GradientStop Color="Transparent" Offset="0.992"/>
								<GradientStop Color="#00B9B9B9"/>
								<GradientStop Color="#FFE0D8D8" Offset="0.91"/>
							</LinearGradientBrush>
						</Border.BorderBrush>
						<Grid>
							<Grid.ColumnDefinitions>
								<ColumnDefinition/>
							</Grid.ColumnDefinitions>
							<Grid.RowDefinitions>
								<RowDefinition Height="0.5*"/>
								<RowDefinition Height="0.5*"/>
								<RowDefinition Height="21"/>
							</Grid.RowDefinitions>
							<TextBlock Grid.Row="2" Text="Basic Text" TextWrapping="Wrap" 
								HorizontalAlignment="Center" VerticalAlignment="Center" 
								Foreground="#FF929292" Grid.ColumnSpan="2" FontSize="9.333"/>
                            
							<!-- ROW 1 -->
							<StackPanel Orientation="Horizontal" d:LayoutOverrides="Height">
								<ComboBox Width="190" VerticalAlignment="Center" Height="24" 
									Style="{StaticResource ToolbarComboBoxStyle}">
									<ComboBoxItem Content="Arial"/>
									<ComboBoxItem Content="Arial Black"/>
									<ComboBoxItem Content="Comic Sans MS"/>
									<ComboBoxItem Content="Courier New"/>
									<ComboBoxItem Content="Georgia"/>
									<ComboBoxItem Content="Lucida Sans Unicode"/>
									<ComboBoxItem Content="Portable User Interface" IsSelected="True"/>
									<ComboBoxItem Content="Times New Roman"/>
									<ComboBoxItem Content="Trebuchet MS"/>
									<ComboBoxItem Content="Verdana"/>
									<ComboBoxItem Content="Webdings"/>
								</ComboBox>
								<ComboBox Height="24" Style="{StaticResource ToolbarComboBoxStyle}"
									VerticalAlignment="Center" Width="62">
									<ComboBoxItem Content="6 pt"/>
									<ComboBoxItem Content="7 pt"/>
									<ComboBoxItem Content="8 pt"/>
									<ComboBoxItem Content="9 pt"  IsSelected="True"/>
									<ComboBoxItem Content="10 pt"/>
									<ComboBoxItem Content="11 pt"/>
									<ComboBoxItem Content="12 pt"/>
									<ComboBoxItem Content="14 pt"/>
									<ComboBoxItem Content="16 pt"/>
									<ComboBoxItem Content="18 pt"/>
									<ComboBoxItem Content="20 pt"/>
									<ComboBoxItem Content="22 pt"/>
									<ComboBoxItem Content="24 pt"/>
									<ComboBoxItem Content="36 pt"/>
									<ComboBoxItem Content="48 pt"/>
									<ComboBoxItem Content="72 pt"/>
								</ComboBox>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" 
									VerticalAlignment="Bottom" Width="28" 
									ImageSource="/OfficerXcel.Content;Component/Icons/Numbers.png" d:LayoutOverrides="HorizontalMargin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" 
									VerticalAlignment="Bottom" Width="28" ImageSource="/OfficerXcel.Content;Component/Icons/Bullets.png"
									d:LayoutOverrides="HorizontalMargin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" 
									VerticalAlignment="Bottom" Width="28" ImageSource="/OfficerXcel.Content;Component/Icons/Linespacing.png"
									d:LayoutOverrides="HorizontalMargin"/>
							</StackPanel>
                            
							<!-- ROW 2 -->
							<StackPanel Grid.Row="1" Orientation="Horizontal" d:LayoutOverrides="Height">
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Bold.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Italic.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Underline.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Strikethrough.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Subscript.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Superscript.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Color.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Align_left.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Align_justify.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28" 
									ImageSource="/OfficerXcel.Content;Component/Icons/Align_right.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28" 
									ImageSource="/OfficerXcel.Content;Component/Icons/Indent.png" d:LayoutOverrides="Height, Margin"/>
								<nRoute_Samples_OfficerXcel_Controls:ImageButton Height="32" 
									Style="{StaticResource ToolbarOfficeImageButtonStyle}" Width="28"
									ImageSource="/OfficerXcel.Content;Component/Icons/Indent_remove.png" d:LayoutOverrides="Height, Margin"/>
							</StackPanel>
						</Grid>
					</Border>
				</StackPanel>
			</Border>
        
        <!-- LINES IMAGE -->
		<Image Height="196" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Row="2" 
			Source="/OfficerXcel.Content;Component/Icons/SideBkgBW.png" Stretch="None" Opacity="0.35" 
			Margin="0,0,0,-24"/>

        <!-- ABOVE THE GRID LINE -->
		<Border BorderThickness="0,0,0,1" BorderBrush="#FFC9CACA" Grid.Row="1">
            
			<Grid>
                
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="159"/>
					<ColumnDefinition Width="85"/>
					<ColumnDefinition/>
				</Grid.ColumnDefinitions>
                
                <!-- CELL TITLE eg. A4 -->
				<Border x:Name="border" Background="White">
					<TextBlock x:Name="textBlock" TextAlignment="Center" VerticalAlignment="Center" 
						Text="{Binding ActiveCellTitle, Mode=OneWay}"/>
				</Border>
                
				
                <Border Background="#FFF6F6F6" Grid.Column="1">
                    <!-- Need to put some buttons here -->
				</Border>
                
                <!-- CELL VALUE -->
				<TextBox BorderThickness="0" TextWrapping="Wrap" BorderBrush="{x:Null}" 
                    Grid.Column="2" FontSize="13.333" 
                    Text="{Binding ActiveCellValue, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
                    IsEnabled="{Binding Worksheet, Converter={StaticResource WorksheetNotNullConverterRelay}, Mode=OneWay}">
					<i:Interaction.Triggers>
						<i:EventTrigger EventName="TextChanged">
							<n:UpdateBindingExplicitlyAction PropertyName="Text"/>
						</i:EventTrigger>
					</i:Interaction.Triggers>
				</TextBox>
                
			</Grid>
		</Border>
        
        <!-- TOP HEADER -->
		<Grid Grid.Row="2" d:IsHidden="True">
            
			<Grid.ColumnDefinitions>
				<ColumnDefinition/>
			</Grid.ColumnDefinitions>
            
            <!-- DATA GRID -->
			<data:DataGrid x:Name="dataGrid" BorderThickness="0" BorderBrush="{x:Null}"
                CanUserReorderColumns="False" CanUserSortColumns="False" HeadersVisibility="All" 
                SelectionMode="Single" MinColumnWidth="40" AutoGenerateColumns="True" 
                ItemsSource="{Binding Worksheet.Rows, Mode=OneWay}" 
                RowDetailsVisibilityMode="Collapsed" RowHeight="23">
                
                <!-- Hides when no worksheet is loaded -->
				<i:Interaction.Behaviors>
					<n:NullValueVisibilityBehavior Value="{Binding Worksheet, Mode=OneWay}"/>
				</i:Interaction.Behaviors>
                
                <!-- Special behaviours that update the active row index and active column header 
                    property in the ViewModel. We've done it this way because SelectedIndex is a
                    readonly property cannot be bound two-way and the current column property
                    is not a DP, hence we need to go through a value relay which is updated
                    via the code-behind
                    -->
				<i:Interaction.Triggers>
					<i:EventTrigger EventName="CurrentCellChanged">
						<xCelBehaviors:SetDataContextPropertyAction PropertyName="ActiveRowIndex" Value="{Binding SelectedIndex,
                            ElementName=dataGrid, Mode=OneWay}"/>
						<xCelBehaviors:SetDataContextPropertyAction PropertyName="ActiveColumnHeader" 
							Value="{Binding Value, Mode=OneWay, Source={StaticResource CurrentColumnHeaderValueRelay}}"/>				
					</i:EventTrigger>
				</i:Interaction.Triggers>
                
			</data:DataGrid>
            
		</Grid>
	</Grid>
</UserControl>